import { get as getVal } from "svelte/store";
import { updateNickname, updateAvatar } from "@api/user";
import { isSigned$, user$ } from "@store/entity/User";
// import { loadingApps } from "./app";

export const updateUserNickname = async (nickname: string) => {
  const $isSigned$ = getVal(isSigned$);
  if (!$isSigned$) {
    return false
  }
  let $user$ = getVal(user$);
  const user = await updateNickname($user$, nickname);
  user$.set(user);
  // await loadingApps()
  return true
}

export const updateUserAvatar = async (avatar: string) => {
  const $isSigned$ = getVal(isSigned$);
  if (!$isSigned$) {
    return false
  }
  let $user$ = getVal(user$);
  const user = await updateAvatar($user$, avatar);
  user$.set(user);
  // await loadingApps()
  return true
}